home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / zcpp_jae.zip / PARMTYPE.C < prev    next >
C/C++ Source or Header  |  1990-07-06  |  2KB  |  80 lines

  1. /*
  2.  
  3.  
  4.  Copyright (C) 1990 Texas Instruments Incorporated.
  5.  
  6.  Permission is granted to any individual or institution to use, copy, modify,
  7.  and distribute this software, provided that this complete copyright and
  8.  permission notice is maintained, intact, in all copies and supporting
  9.  documentation.
  10.  
  11.  Texas Instruments Incorporated provides this software "as is" without
  12.  express or implied warranty.
  13.  
  14.  
  15.  *
  16.  * Edit history
  17.  * Created: LGO 30-Mar-89 -- Initial design and implementation.
  18.  * 
  19.  * The PARMTYPE defmacro
  20.  *
  21.  * CPP defmacro for constructing parameterized types
  22.  * The input looks like  name<arg1, arg2, argn>
  23.  * The output looks like name_arg1_arg2_argn
  24.  * An asterisk in an arg is converted to a capital P.
  25.  *
  26.  */
  27.  
  28. #include "defmacio.h"
  29.  
  30. #define BSIZE 512
  31.  
  32. /*
  33.  * Convert a paramertized name string into its c++ name
  34.  */
  35. int parmstring(parms)
  36.   char* parms;
  37. {
  38.   char* inp = parms;
  39.   char* outp = parms;
  40.   int bracket_level = 0;
  41.   char c;
  42.   for(; (c = *inp) != EOS; inp++) {
  43.     switch (c) {
  44.     case '<': bracket_level++; *outp++ = '_'; break;
  45.     case '>': bracket_level--; *outp++ = '_'; break;
  46.     case '*': *outp++ = 'P'; break;      /* Convert * to P */
  47.     case '.': *outp++ = 'x'; break;      /* Convert . to x */
  48.     case ',': *outp++ = '_'; break;      /* Convert , to _ */
  49.     case '_': *outp++ = '_'; break;      /* _ is _ */
  50.     case '$': *outp++ = '$'; break;      /* $ is $ */
  51.     default:            /* Throw out anything else not alpha-numeric */
  52.       if(isalnum(c)) *outp++ = c;
  53.     }
  54.   }
  55.   if(*(outp-1) == '_') outp--;          /* Trim trailing _ */
  56.   *outp = EOS;
  57.   if(bracket_level == 0) {
  58.     return 0;
  59.   } else {
  60.     fprintf(stderr, "parmtype: Unexpeced EOF for %s\n", parms);
  61.     return 1;
  62.   }
  63. }
  64.  
  65. parmtype(argc, argv)
  66.      int argc;
  67.      char* argv[];
  68. {
  69.   char c;
  70.   char out[BSIZE];
  71.   char* outp = out;
  72.  
  73.   while((c=getchar()) != EOF) *outp++ = c;
  74.   *outp = EOS;
  75.   if(parmstring(out) != 0) 
  76.     return 1;
  77.   puts(out);
  78.   return (0);
  79. }
  80.